let express = require("express");
let mongoose = require("mongoose");
let bodyParser = require('body-parser');  //解析 HTTP 请求
let morgan = require('morgan');  //输出该请求的日志信息

let upload = require('./router/upload');
let login = require('./router/login');
let publish = require('./router/publish');
let myhome = require('./router/myhome');
let allMessage = require('./router/allMessage');

let app = express();

mongoose.connect('mongodb://localhost/lostAndFound', { useNewUrlParser: true }, function(err){
    if(err){
        console.log("数据库连接失败! 可能是数据库未开启")
    }else{
        console.log("数据库连接成功！")
    }
});

app.use(bodyParser.json());
app.use(morgan('dev'));

app.use('/', login);
app.use('/api', upload);
app.use('/publish', publish);
app.use('/myhome', myhome);
app.use('/allMessage', allMessage);

app.listen(3000, function(){
    console.log("server run on port 3000");
})